﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace docmgr.WinForm
{
    public partial class PasswordModify : Form
    {

        docmgr.BLL.User userbll = new BLL.User();
        public PasswordModify()
        {
            InitializeComponent();
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel, ((byte)(134)));

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(Common.EncryptCode(textBox1.Text)!=(String)Common.curUser.Rows[0]["Password"])
            {
                MessageBox.Show("与原始口令不对应");
                return;
            }

            if(textBox2.Text=="" )
            {
                MessageBox.Show("不能为空");
                return;
            }
            if ( textBox2.Text != textBox3.Text )
            {
                MessageBox.Show("请保证两次密码一样");
                return;
            }
            if (textBox2.Text.Length < 4)
            {
                MessageBox.Show("请保证密码长度大于4");
                return;
            }


            Common.curUser.Rows[0]["Password"] = Common.EncryptCode(textBox2.Text);

            userbll.Update(Common.curUser);

            string currentPath = AppDomain.CurrentDomain.BaseDirectory;
            string exepath = currentPath + "conf.ini";
            IniFile ini = new IniFile(exepath);
            String autologin = ini.ReadInivalue("自动登录", "autologin");

            if (autologin.Equals("true"))
            {
                ini.WriteInivalue("自动登录", "autologin", "true");
                ini.WriteInivalue("自动登录", "username", Program.userName);
                ini.WriteInivalue("自动登录", "password", textBox2.Text);
            }

            MessageBox.Show("更新成功。");
            this.Close();

        }

        private void PasswordModify_Load(object sender, EventArgs e)
        {
            
        }
    }
}
